package com.mtx.controller;

import com.mtx.iocHomeWork.IGeLi;
import com.mtx.iocHomeWork.LiuDeHua;
import com.mtx.iocHomeWork.constructorInjection.ConstructorInjectionMoAttack;
import com.mtx.iocHomeWork.interfaceInjection.InterfaceInjectionMoAttack;
import com.mtx.iocHomeWork.setterInjection.SetterInjectionMoAttack;
import com.mtx.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;

@RestController
@RequestMapping("/Ioc")
public class IocHomeWorkController {
    @GetMapping("doNotRelyOnSpring")
    public Message doNotRelyOnSpring() {
        IGeLi geLi = new LiuDeHua();
        ConstructorInjectionMoAttack constructorInjectionAttack = new ConstructorInjectionMoAttack(geLi);
        SetterInjectionMoAttack setterInjectionMoAttack = new SetterInjectionMoAttack();
        setterInjectionMoAttack.setGeLi(geLi);
        InterfaceInjectionMoAttack interfaceInjectionMoAttack = new InterfaceInjectionMoAttack();
        interfaceInjectionMoAttack.injectGeli(geLi);
        ArrayList<String> list = new ArrayList<>(Arrays.asList(constructorInjectionAttack.cityGateAsk(),
                setterInjectionMoAttack.cityGateAsk(),
                interfaceInjectionMoAttack.cityGateAsk()));
        return Message.success(list);
    }
    @Autowired
    ConstructorInjectionMoAttack constructorInjectionMoAttack;
    @Autowired
    InterfaceInjectionMoAttack interfaceInjectionMoAttack;
    @Autowired
    SetterInjectionMoAttack setterInjectionMoAttack;
    @GetMapping("RelyOnSpring")
    public Message relyOnSpring() {
        ArrayList<String> list = new ArrayList<>(Arrays.asList(constructorInjectionMoAttack.cityGateAsk(),
                setterInjectionMoAttack.cityGateAsk(),
                interfaceInjectionMoAttack.cityGateAsk()));
        return Message.success(list);
    }
}
